package com.demo.datastructure.tree;

/**
 * @description: leetcode 26 树的子结构
 * @author: ljr
 * @time: 2021/6/11 17:18
 */
public class TreeConstainDemo {


    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A == null || B == null){ return true; }
        return isSubStructure2(A,B);
    }


    private boolean isSubStructure2(TreeNode A, TreeNode B) {
         if(A.val == B.val){
             return true;
         }

         if(A.val < B.val){
             return isSubStructure2(A, B);
         }
         return true;
    }

    public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
}
